package com.weilive.platform;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.weilive.core.facade.Bootstrap;
import com.weilive.core.netty.http.HttpServletManager;
import com.weilive.core.netty.spring.NettySpringServer;
import com.weilive.core.protocol.json.JsonCodec;
import com.weilive.core.protocol.protobuf.ProtobufCodec;

public class PlatformMain
{
    private static final Logger logger = LoggerFactory.getLogger(PlatformMain.class);
    public static void main(String[] args) throws Exception
    {
        
        // 加载Spring
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:/application-context.xml");
        
        // 加载各个启动器
        for (Bootstrap bootstrap : context.getBeansOfType(Bootstrap.class).values())
        {
            bootstrap.loadBySpring(context);
        }
        
        // 加载协议解析器
        JsonCodec.loadBySpring(context);
        ProtobufCodec.loadBySpring(context);
        HttpServletManager.loadBySpring(context);
        
        // 启动各个网络服务
        for (NettySpringServer springServer : context.getBeansOfType(NettySpringServer.class).values())
        {
            springServer.getServer().start();
        }
        logger.info("--------------平台服务器启动成功--------------");
    }
}
